import 'package:dio/dio.dart';

import 'http_code.dart';

class HttpResponse<T> {
  T? data;
  String? message;
  int? code;
  DioExceptionType? type;
  int timeStamp;

  HttpResponse({
    this.data,
    this.code,
    this.message,
    this.type,
    this.timeStamp=0,
  });

  factory HttpResponse.fromJson(Map? json) => HttpResponse(
        data: json?["data"],
        code: json?["code"],
        timeStamp: json?["timeStamp"]??0,
        message: json?["msg"] ?? json?["message"],
      );

  bool get isSuccess{
    return HttpCode.code200==code && data!=null;
  }

  String get codeAndMsg{
    return "${code??""} $message";
  }
}
